home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / pbmplus / pbm / pbmtoptx.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  1.9 KB  |  101 lines

  1. /* pbmtoptx.c - read a portable bitmap and produce a Printronix printer file
  2. **
  3. ** Copyright (C) 1988 by Jef Poskanzer.
  4. **
  5. ** Permission to use, copy, modify, and distribute this software and its
  6. ** documentation for any purpose and without fee is hereby granted, provided
  7. ** that the above copyright notice appear in all copies and that both that
  8. ** copyright notice and this permission notice appear in supporting
  9. ** documentation.  This software is provided "as is" without express or
  10. ** implied warranty.
  11. */
  12.  
  13. #include "pbm.h"
  14.  
  15. static void putinit ARGS(( void ));
  16. static void putbit ARGS(( bit b ));
  17. static void putrest ARGS(( void ));
  18. static void putitem ARGS(( void ));
  19.  
  20. void main( argc, argv )
  21. int argc;
  22. char *argv[];
  23.     {
  24.     FILE *ifp;
  25.     register bit *bitrow, *bP;
  26.     int rows, cols, format, row, col;
  27.     char *usage = "[pbmfile]";
  28.  
  29.     pbm_init( &argc, argv );
  30.  
  31.     if ( argc > 2 )
  32.     pm_usage( usage );
  33.  
  34.     if ( argc == 2 )
  35.     ifp = pm_openr( argv[1] );
  36.     else
  37.     ifp = stdin;
  38.  
  39.     pbm_readpbminit( ifp, &cols, &rows, &format );
  40.     bitrow = pbm_allocrow( cols );
  41.  
  42.     putinit( );
  43.     for ( row = 0; row < rows; row++ )
  44.     {
  45.     pbm_readpbmrow( ifp, bitrow, cols, format );
  46.         for ( col = 0, bP = bitrow; col < cols; col++, bP++ )
  47.         putbit( *bP );
  48.     putrest( );
  49.     putchar( 5 );
  50.     putchar( '\n' );
  51.         }
  52.  
  53.     pm_close( ifp );
  54.     
  55.     exit( 0 );
  56.     }
  57.  
  58. static char item;
  59. static int bitsperitem, bitshift;
  60.  
  61. static void
  62. putinit( )
  63.     {
  64.     bitsperitem = 0;
  65.     item = 64;
  66.     bitshift = 0;
  67.     }
  68.  
  69. #if __STDC__
  70. static void
  71. putbit( bit b )
  72. #else /*__STDC__*/
  73. static void
  74. putbit( b )
  75.     bit b;
  76. #endif /*__STDC__*/
  77.     {
  78.     if ( bitsperitem == 6 )
  79.     putitem( );
  80.     if ( b == PBM_BLACK )
  81.     item += 1 << bitshift;
  82.     bitsperitem++;
  83.     bitshift++;
  84.     }
  85.  
  86. static void
  87. putrest( )
  88.     {
  89.     if ( bitsperitem > 0 )
  90.     putitem( );
  91.     }
  92.  
  93. static void
  94. putitem( )
  95.     {
  96.     putchar( item );
  97.     bitsperitem = 0;
  98.     item = 64;
  99.     bitshift = 0;
  100.     }
  101.